// proxyOrder.js
const app = getApp()
const util = require("../../utils/util.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    sn:'',
    income: {},
    list: [],
    pagenum: 1,

  },
  incomeStatistics: function () {
    var that = this;
    var data = { 
      page: that.data.pagenum,
      sn:that.data.sn,
      openid: app.globalData.openId
   };
    app.post('agent/deviceOrderInfo', data).then((res) => {
      if (res.code == 200) {
        var list = that.data.list;
        var dataArr = res.data.data;
        list = list.concat(dataArr)
        that.setData({
          income: res.data.info,
          list: list
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg);
      wx.showToast({
        title: "网络错误",
        icon: 'loading',
        duration: 2000
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      sn:options.sn
    })
    this.incomeStatistics();  
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      pagenum: 1
    })
    this.incomeStatistics();
  },
  /**
     * 页面上拉触底事件的处理函数
     */
  onReachBottom: function () {
    var that = this;
    var pagenum = that.data.pagenum + 1; //获取当前页数并+1
    that.setData({
      pagenum: pagenum, //更新当前页数
    })
    that.incomeStatistics();//重新调用请求获取下一页数据
  }
})